﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Jemgine.Gui
{
    public class FlowLayout
    {
        Rectangle CoverageArea;
        float NextX, NextY, CurrentY;

        public void BeginLayout(Rectangle Area)
        {
            CoverageArea = Area;
            NextX = 0;
            NextY = 0;
            CurrentY = 0;
        }

        public Rectangle PositionItem(Vector2 Dimensions)
        {
            Rectangle R = new Rectangle(NextX, CurrentY, Dimensions.X, Dimensions.Y);
            if (R.Right > CoverageArea.Width)
            {
                R.X = 0;
                NextX = 0;
                R.Y = NextY;
                CurrentY = NextY;
            }

            NextX = NextX + R.Width;
            if (NextY < R.Bottom) NextY = R.Bottom;

            R.X += CoverageArea.X;
            R.Y += CoverageArea.Y;

            return R;
        }
    }
}
